//package com.ums.upos;
//
//import android.content.ComponentName;
//import android.content.Context;
//import android.content.Intent;
//import android.content.ServiceConnection;
//import android.os.Bundle;
//import android.os.IBinder;
//import android.os.RemoteException;
//import android.support.test.InstrumentationRegistry;
//import android.support.test.filters.LargeTest;
//import android.support.test.rule.ServiceTestRule;
//import android.support.test.runner.AndroidJUnit4;
//
//import com.ums.upos.service.DeviceServiceEngineService;
//import com.ums.upos.uapi.device.pinpad.OnPinPadInputListener;
//import com.ums.upos.uapi.device.pinpad.PinAlgorithmMode;
//import com.ums.upos.uapi.device.pinpad.PinPad;
//import com.ums.upos.uapi.device.pinpad.PinPadType;
//import com.ums.upos.uapi.engine.DeviceServiceEngine;
//
//import org.junit.AfterClass;
//import org.junit.Before;
//import org.junit.Rule;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//
///**
// * Created by Administrator on 2017/4/24.
// */
//
//@RunWith(AndroidJUnit4.class)
//@LargeTest
//public class PinpadServiceTest {
//    private static PinPad pinPad = null;
//    private DeviceServiceEngine mDeviceHandle = null;
//    private static boolean bIsBusy = false;
//
//    @Rule
//    public ServiceTestRule mServiceRule = new ServiceTestRule();
//
//    @AfterClass
//    public static void afterClass() throws Exception{
//        Thread.sleep(10 * 1000, 0);
//    }
//
//    @Before
//    public void start() {
//        if (null != pinPad)
//            return;
//        ServiceConnection conn = new ServiceConnection() {
//            @Override
//            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
//                mDeviceHandle = DeviceServiceEngine.Stub.asInterface(iBinder);
//            }
//
//            @Override
//            public void onServiceDisconnected(ComponentName componentName) {
//                pinPad = null;
//            }
//        };
//
//        Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), DeviceServiceEngineService.class);
//        try {
//            mServiceRule.bindService(intent, conn, Context.BIND_AUTO_CREATE);
//            Bundle loginBundle = new Bundle();
//            loginBundle.putInt("workMode", 0);
//            mDeviceHandle.login(loginBundle, "00000001");
//            pinPad = mDeviceHandle.getPinPad();
//            Thread.sleep(5 * 1000, 0);
//        } catch (Exception e) {
//            pinPad = null;
//            e.printStackTrace();
//        }
//    }
//
//    @Test
//    public void test_inputOnlinePin() {
//        bIsBusy = true;
//        try {
//            pinPad.initPinPad(PinPadType.INTERNAL);
//            pinPad.inputOnlinePin("1234567890123".getBytes(), 0, PinAlgorithmMode.ISO9564FMT1, new OnPinPadInputListener.Stub() {
//                @Override
//                public void onInputResult(int retCode, byte[] data) throws RemoteException {
//                    bIsBusy = false;
//                }
//
//                @Override
//                public void onSendKey(byte keyCode) throws RemoteException {
//                    Intent intent = new Intent();
//                    Bundle bundle = new Bundle();
//                    bundle.putString("amount", "000000000001");
//                    intent.putExtras(bundle);
//                    intent.setAction("com.ums.tss.showamount");
//                    InstrumentationRegistry.getTargetContext().sendBroadcast(intent);
//                }
//            });
//            while (bIsBusy){
//                Thread.sleep(1 * 1000, 0);
//            }
//            bIsBusy = true;
//            pinPad.inputOnlinePin("1234567890123".getBytes(), 0, PinAlgorithmMode.ISO9564FMT1, new OnPinPadInputListener.Stub() {
//                @Override
//                public void onInputResult(int retCode, byte[] data) throws RemoteException {
//                    bIsBusy = false;
//                }
//
//                @Override
//                public void onSendKey(byte keyCode) throws RemoteException {
//                    Intent intent = new Intent();
//                    Bundle bundle = new Bundle();
//                    bundle.putString("amount", "000000000002");
//                    intent.putExtras(bundle);
//                    intent.setAction("com.ums.tss.showamount");
//                    InstrumentationRegistry.getTargetContext().sendBroadcast(intent);
//                }
//            });
//            while (bIsBusy){
//                Thread.sleep(1 * 1000, 0);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}
